package Library.operation;

import Library.Book;
import Library.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("还书");
        Scanner scanner = new Scanner(System.in);
        int id = scanner.nextInt();
        if(id < 0 || id > bookList.getSize() - 1){
            System.out.println("输入错误");
            return;
        }
        if(bookList.getBook(id) == null){
            return;
        }
        Book book = bookList.getBook(id);
        if(!book.isBorrow()){
            System.out.println("该书未借出,不能归还");
            return;
        }
        book.setBorrow(false);
        System.out.println("还书成功");

    }
}
